package com.sans.start;

import org.junit.Test;

import java.util.Random;

/**
 * @author Sans
 */
public class BaseOperatorsTest {
    @Test
    public void baseOperator() {
        System.out.println(10 / 4);
        System.out.println(10.0 / 4);
        System.out.println(0 % 3);
        System.out.println(5 % -3);
        System.out.println(-5 % 3);
    }

    @Test
    public void selfOperator() {
        int a = 1;
        System.out.println(a++);
        System.out.println(++a);

        short sh = 100;
        short sh1 = sh++;
        short sh2 = ++sh;
        System.out.println(sh1);
        System.out.println(sh2);
    }

    @Test
    public void assignOperator() {
        int a = 1;
        System.out.println(a += 7);
        System.out.println(a -= 5);
        System.out.println(a *= 3);
        System.out.println(a /= 5);
        System.out.println(a %= 7);
        System.out.println(a);
    }

    @Test
    public void relationOperator() {
        int a = 7;
        System.out.println(a > 9);
        System.out.println(a == 9);
        System.out.println(a != 9);
        System.out.println(a < 9);
        System.out.println(a >= 9);
        System.out.println(a <= 9);
    }

    @Test
    public void logic() {
        int a = 5;
        System.out.println(a < 7 && a == 5);
        System.out.println(a == 7 || a != 5);
        System.out.println(!(a == 7));
        System.out.println(a == 7 || a == 1 && a == 5);
    }

    @Test
    public void bit() {
        int a = 7;
        System.out.println(a != 7 & a++ == 7);
        System.out.println(a);
    }
    @Test
    public void ternary(){
        int score = 59;
        String result = (score > 100 || score < 0) ? "分数有问题" : (score >= 80 ? "优秀" : (score >= 60 ? "及格" : "不及格"));
        System.out.println(result);
    }
    @Test
    public void mathApi() {
        System.out.println(Math.max(1, 2));
        System.out.println(Math.min(1, 2));
        System.out.println(Math.ceil(1.1));
        System.out.println(Math.floor(1.9));
        System.out.println(Math.abs(-5));
        System.out.println(Math.round(-11.5));
        System.out.println(Math.pow(2, 3));
    }
    @Test
    public void randomApi(){
        Random random = new Random();
        System.out.println(random.nextDouble());
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
    }
}
